package com.example.secondhandshop.ui.adapter;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.example.secondhandshop.ui.fragment.BoughtFragment;
import com.example.secondhandshop.ui.fragment.PostedFragment;
import com.example.secondhandshop.ui.fragment.SoldFragment;

public class ViewPagerAdapter extends FragmentPagerAdapter {

    public ViewPagerAdapter(FragmentManager fm) {
        super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    }

    @Override
    public Fragment getItem(int position) {
        // 返回对应位置的 Fragment
        switch (position) {
            case 0:
                return new BoughtFragment();
            case 1:
                return new SoldFragment();
            case 2:
                return new PostedFragment();
            default:
                return null;
        }
    }

    @Override
    public int getCount() {
        // 返回标签的数量
        return 3;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        // 返回对应位置的标签标题
        switch (position) {
            case 0:
                return "我买到的";
            case 1:
                return "我卖出的";
            case 2:
                return "我发布的";
            default:
                return null;
        }
    }
}